{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a791a86b",
   "metadata": {},
   "outputs": [],
   "source": [
    "alipay = input(\"请输入你的余额：\")\n",
    "商品列表 = [\n",
    "    [\"棒棒糖\",5],\n",
    "    [\"可乐 \",10],\n",
    "    [\"糖葫芦\",15],\n",
    "    [\"珍珠奶茶\",20],\n",
    "    [\"发卡\",8]\n",
    "]\n",
    "\n",
    "购物车 = [] # 当用户选择商品时，添加进购物车\n",
    "\n",
    "while True:\n",
    "    print(\"商品列表\")\n",
    "    for i in 商品列表:\n",
    "        print(\"商品编号: %s, 商品名称: %s, 商品价格: %s 元\"%(商品列表.index(i),i[0],i[1]))\n",
    "\n",
    "    user_choose = input(\"请输入商品编号：\")\n",
    "    \n",
    "    # 条件判断1: 判断用户输入是否为商品编号\n",
    "    if user_choose.isdigit():\n",
    "        \n",
    "        # 条件判断2: 商品价格 和 余额，两种可能\n",
    "        if 商品列表[int(user_choose)][1] < int(alipay):\n",
    "            alipay = int(alipay) - 商品列表[int(user_choose)]\n",
    "            购物车.append商品列表[int(user_choose)]\n",
    "            print(\"%s 已购买成功, 您的余额还有: %s 元\"%(商品列表[int(user_choose)][0],alipay))\n",
    "        else:\n",
    "            print(\"就%s元，还想购买%s，逛一逛其他商品吧~\"%(alipay,商品列表[int(user_choose)][0],))\n",
    "            \n",
    "    elif user_choose == \"quit\":\n",
    "    \n",
    "        print(\"您的购物车: %s, 您的余额还剩: %s 元\"%(购物车,alipay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入正确的商品编号，或者输入‘quit’退出\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d86e8b66",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
